package com.util.library.model;

import java.util.Timer;
import java.util.TimerTask;

import com.util.library.network.OnNetWorkTimeOutListener;

import android.util.Log;

public class Transaction extends Model {
	private int idSent = 0;
	private String methodSent = "";
	private Model model = null;

	private String messageSent = "";
	private String messageReceived = "";

	private OnNetWorkTimeOutListener onNetworkTimeOutListener = null;
	private boolean isFail = false;

	private Timer timerOut = null;

	public Transaction() {
		super();
	}

	public int getIdSent() {
		return idSent;
	}

	public Transaction(OnNetWorkTimeOutListener failListener, int timeOut) {
		onNetworkTimeOutListener = failListener;
		TimerTask timerTask = new TimerTask() {

			@Override
			public void run() {
				isFail = true;
				Log.d("Transaction", "TIME OUT SMS!!!!!!!!!!!!!");
				onNetworkTimeOutListener.onNetworkTimeOut(Transaction.this);
			}
		};

		timerOut = new Timer();
		timerOut.schedule(timerTask, timeOut);
	}

	public void success() {
		isFail = false;
		if (timerOut != null) {
			timerOut.cancel();
			timerOut = null;
		}
	}

	public void setIdSent(int idSent) {
		this.idSent = idSent;
	}

	public String getMethodSent() {
		return methodSent;
	}

	public void setMethodSent(String methodSent) {
		this.methodSent = methodSent;
	}

	public Model getModel() {
		return model;
	}

	public void setModel(Model model) {
		this.model = model;
	}

	public String getMessageSent() {
		return messageSent;
	}

	public void setMessageSent(String messageSent) {
		this.messageSent = messageSent;
	}

	public String getMessageReceived() {
		return messageReceived;
	}

	public void setMessageReceived(String messageReceived) {
		this.messageReceived = messageReceived;
	}

	public boolean isFail() {
		return isFail;
	}

	public void setFail(boolean isFail) {
		this.isFail = isFail;
	}
}
